import { fileURLToPath, URL } from 'node:url'
import Components from 'unplugin-vue-components/vite'
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers'
import vue from '@vitejs/plugin-vue'
import { defineConfig, loadEnv } from 'vite'
// 下面插件的作用可以给setup语法糖的组件添加name属性起组件名
import vueSetupExtend from 'vite-plugin-vue-setup-extend'
// 自动导入
import AutoImport from 'unplugin-auto-import/vite'
/* import { config } from 'node:process'
import router from '@/router' */

// https://vitejs.dev/config/

export default ({ mode }) => {
  console.log(loadEnv(mode, './'))
  return defineConfig({
    plugins: [
      AutoImport({
        imports: ['vue', 'vue-router'],
        eslintrc: {
          enabled: true
        }
      }),
      vueSetupExtend(),
      vue(),
      Components({
        resolvers: [
          AntDesignVueResolver({
            importStyle: false // css in js
          })
        ]
      })
    ],
    resolve: {
      alias: {
        '@': fileURLToPath(new URL('./src', import.meta.url))
      }
    }
  })
}

/* export default ({ mode }) => {
  console.log(loadEnv(mode, './'))
  return defineConfig({
    server: {
      port: 8888,
      proxy: {
        '/api': {
          target: config.VITE - APP - URL,
          changeOrigin: true
        }
      }
    }
  })
} */
